package com.gzxxgl.common.interceptor;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;

import com.gzxxgl.enu.TableSequence;
import com.gzxxgl.model.data.SysDict;
import com.gzxxgl.model.data.SysLog;
import com.gzxxgl.model.data.User;
import com.gzxxgl.util.IpHelper;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

/**
 * 
 */
public class LogInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation ai) {
		
		try {
			ai.invoke();
		} catch (Exception e) {
			
			e.printStackTrace();
		}finally{
			
		User user = ai.getController().getSessionAttr("currentuser");
		SysLog log = new SysLog();
	
		if(user != null){
			
			log.set("logid", TableSequence.log_id_sequence.name() + TableSequence.val);
			
			 HttpServletRequest request = ai.getController().getRequest();
			  
			String ip= IpHelper.getIpAddr(request);
			
			log.set("dlsj", new Timestamp(System.currentTimeMillis()));
			log.set("ipaddr", ip);
			log.set("url", ai.getControllerKey()+ai.getMethodName());
			
			log.set("ygbm", user.get("ygbm"));
			log.set("xm", user.get("xm"));
			log.set("dlmm", user.get("pasword"));
			Integer did= Integer.parseInt(user.getRight()); 
			log.set("yhqx",SysDict.dao.querybyid(did).getDname());
		
			log.set("dlsjjl",  ai.getController().getAttr("dlsjjl"));
			@SuppressWarnings("unused")
			boolean flag = log.save();
		}
		
		
		}
	}
}
